package trading.spring;

import java.util.Map;

import javax.annotation.Resource;

import org.apache.velocity.app.VelocityEngine;
import org.apache.velocity.exception.VelocityException;
import org.springframework.stereotype.Service;
import org.springframework.ui.velocity.VelocityEngineUtils;
import org.springframework.web.servlet.view.velocity.VelocityConfig;

@Service
public class VelocityServiceImpl implements VelocityService {

    private VelocityEngine _velocityEngine;

    /**
     * Set the Velocity config.
     * 
     * @param velocityConfig A {@link VelocityConfig} object
     */
    @Resource(name = "velocityConfig")
    public void setVelocityConfig(VelocityConfig velocityConfig) {
        this._velocityEngine = velocityConfig.getVelocityEngine();
    }
    
    public void setVelocityEngine(VelocityEngine velocityEngine) {
        this._velocityEngine = velocityEngine;
    }

    public String mergeTemplateIntoString(Map<String, Object> model, String templateLocation) throws VelocityException {
        return VelocityEngineUtils.mergeTemplateIntoString(_velocityEngine, templateLocation, model);
    }

}
